<template>
  <div class="integralShiftRecord">
    <c-title :text="pageTitle" :backQuery="this.$route.query.ind" :url="'integralShiftIndex'"></c-title>
    <div class="list" v-if="page_list.length">
      <div class="lis" v-for="(item, index) in page_list" :key="index">
        <div class="blod flex-j-sb flex-a-c">
          <div class="left">兑换ID:{{ item.id }}</div>
          <div class="right">{{ item.amount }}</div>
        </div>
        <div class="txt flex-j-sb flex-a-c">
          <div class="left">兑换时间:{{ item.created_at }}</div>
          <div class="right">{{ item.status_name }}</div>
        </div>
        <div class="txt" v-if="item.status == 1">
          <div class="left flex">
            {{ lock_name }}倒计：
            <van-count-down :time="timeSet(item.unlock_second)" format="DD:HH:mm:ss">
              <template #default="timeData">
                <span class="blockDay">{{ `${timeData.days}天` }}</span>
                <span class="block">{{ timeData.hours < 10 ? `0${timeData.hours}` : timeData.hours }}</span>
                <span class="colon">:</span>
                <span class="block">{{ timeData.minutes < 10 ? `0${timeData.minutes}` : timeData.minutes }}</span>
                <span class="colon">:</span>
                <span class="block">{{ timeData.seconds < 10 ? `0${timeData.seconds}` : timeData.seconds }}</span>
              </template>
            </van-count-down>
          </div>
        </div>
      </div>
    </div>
    <van-empty image="search" description="暂无更多" v-else />
  </div>
</template>
<script>
import { scrollMixin } from "../../utils/mixin";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      pageTitle: "兑换记录",
      page_list: [],
      lock_name: "",
      page: 1,
      total_page: 0,
      isLoadMore: true
    };
  },
  activated() {
    this.page = 1;
    this.total_page = 0;
    this.getData();
  },
  methods: {
    timeSet(unlock_second) {
      return `${Number(unlock_second)}000`;
    },
    getData() {
      $http
        .post(
          "plugin.integral-shift.frontend.modules.detail.controllers.records.index",
          {
            pool_id: this.$route.params.pool_id
          },
          "."
        )
        .then(res => {
          if (res.result == 1) {
            this.page_list = res.data.page_list.data;
            this.lock_name = res.data.otherParams.lock_name;
            let title = `${res.data.otherParams.pool_title}兑换记录`;
            this.pageTitle = title;
            this.fun.setWXTitle(title);
            this.isLoadMore = true;
            this.total_page = res.data.page_list.last_page;
            if (!this.total_page) {
              this.page = 0;
            }
          } else {
            this.$toast(res.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getMoreData() {
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        $http
          .post(
            "plugin.integral-shift.frontend.modules.detail.controllers.records.index",
            {
              pool_id: this.$route.params.pool_id,
              page: this.page
            },
            "."
          )
          .then(res => {
            if (res.result == 1) {
              this.isLoadMore = true;
              this.page_list = this.page_list.concat(res.data.page_list.data);
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
              this.$toast(res.msg);
            }
          })
          .catch(error => {
            console.log(error);
          });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.colon {
  display: inline-block;
  margin: 0 0.125rem;
  color: #f15353;
  border-radius: 0.13rem;
}
.block {
  display: inline-block;
  width: 1.13rem;
  color: #fff;
  font-size: 0.81rem;
  text-align: center;
  background-color: #f15353;
  border-radius: 0.13rem;
}
.blockDay {
  display: flex;
  align-items: center;
  color: #f15353;
  font-size: 0.81rem;
  text-align: center;
  margin-right: 0.31rem;
}
.van-count-down {
  display: flex;
}
.list {
  margin: 0 0.75rem;
  .lis {
    padding: 0.63rem 0.66rem;
    border-radius: 0.5rem;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-top: 0.63rem;
    .blod {
      flex: 1;
      font-weight: 500;
    }
    .txt {
      flex: 1;
      font-size: 0.81rem;
      color: #6e6e79;
      margin-top: 0.5rem;
    }
    .left {
      flex: 1;
      text-align: left;
    }
  }
}
</style>
